// use tauri::AppHandle;
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
// use tauri_plugin_log::{Target, TargetKind};
use tauri_plugin_autostart::MacosLauncher;
use tauri::{Emitter};

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Greet {
    name: String
}


#[tauri::command]
fn greet_event(name: &str, app_handle: tauri::AppHandle) {
    let msg = format!("Hello, {}! You've been greeted from Rust!", name);
    let _ = app_handle.emit("greet_event", msg);
}


#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"])))
        // .plugin(tauri_plugin_log::Builder::new().build())
        .plugin(tauri_plugin_window_state::Builder::new().build())
        .plugin(tauri_plugin_upload::init())
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_websocket::init())
        .plugin(tauri_plugin_http::init())
        .plugin(tauri_plugin_opener::init())
        .setup(|app| {
            if cfg!(debug_assertions) {
                app.handle().plugin(
                    tauri_plugin_log::Builder::default()
                        .level(log::LevelFilter::Info)
                        .build(),
                )?;
            }
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![greet,greet_event])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
